package com.ext.aic.ui;

import android.os.Bundle;
import android.view.View;

import com.ext.aic.R;
import com.ext.aic.databinding.SettingLayoutBinding;
import com.ext.aic.handler.AppUpdateHandler;
import com.ext.aic.utils.AppUtils;
import com.ext.aic.utils.RedirectUtils;

public class SettingActivity extends BaseActivity {

    private SettingLayoutBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = View.inflate(this, R.layout.setting_layout, null);
        binding = SettingLayoutBinding.bind(view);
        setContentView(binding.getRoot());
        bindView();
        bindAppVersion();
    }

    private void bindAppVersion() {
        String versionName = AppUtils.getInstance().getVersionName();
        binding.versionTv.setText(getString(R.string.app_version, versionName));
    }

    private void bindView() {
        binding.topView.backIv.setOnClickListener(v -> finish());
        binding.topView.titleTv.setText(R.string.setting);
        binding.aiSeparateSetting.setOnClickListener(this::onAISeparateSettingOnClick);
        binding.whiteListSettingLl.setVisibility(View.VISIBLE);
        binding.whiteListSettingLl.setOnClickListener(this::onWhiteListSettingClick);
        binding.checkUpdateLl.setOnClickListener(this::onCheckUpdateClick);
    }

    public void onCheckUpdateClick(View view) {
        AppUpdateHandler appUpdateHandler = new AppUpdateHandler();
        appUpdateHandler.checkUpdate(this, true);
    }

    public void onWhiteListSettingClick(View view) {
        RedirectUtils.getInstance().startActivity(this, WeChatWhiteListActivity.class);
    }

    public void onAISeparateSettingOnClick(View view) {
        RedirectUtils.getInstance().startActivity(this, AISeparateSettingActivity.class);
    }
}
